package edu.sctu.jarime.june.day20150616.KnowURL;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user19 on 2015/6/16.
 */
public class URLUtil {
    public static String utilByURL(String path) throws Exception {
        URL url = new URL(path);
        InputStream inputStream = url.openStream();
        int a;
        byte[] butffer = new byte[2014];
        while ((a = inputStream.read(butffer)) != -1) {
            System.out.println(new String(butffer, 0, a, "utf-8"));
        }
        return path;
    }


    public static void utilByURLConnection(String path) throws Exception{

        URL url = new URL(path);
        URLConnection connection = url.openConnection();
        connection.connect();
        InputStream inputStream = connection.getInputStream();
        int b;
        byte[] butffer = new byte[2014];
        while ((b = inputStream.read(butffer)) != -1) {
            System.out.println(new String(butffer, 0, b, "utf-8"));
            System.out.println(connection.getContentEncoding());
            System.out.println(connection.getContentLength());
            System.out.println(connection.getContentType());
        }

    }
}


